<template>
  <el-container class="license-warp">
    <div class="top">
      <FormPanel
        ref="formPanel"
        :list="formList"
        :cols="2"
        :labelWidth="110"
        formType="add"
        :isSubmitBtn="false"
        @formChange="getClssList"
      />
    </div>
    <div class="footer">
      <AjaxButton :click="saveDialog" type="primary" :loading="addBtnState">确 定</AjaxButton>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </el-container>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getClssList } from '@/api/repair/repairReception/customer';
import { getEmployeeNo, getUser, getUserId } from '@/assets/js/auth';
import { addHistory } from '@/api/derived/insurance/insurancePolicy';

export default {
  name: 'Policy',
  mixins: [dictionary],
  props: ['TBcode'],

  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      addBtnState: null,
      type: '',
      name: ''
    };
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '投保单号',
          fieldName: 'proposalCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '接触内容',
          fieldName: 'trackContent',
          placeholder: '',
          rows: 2,
          maxlength: 120,
          rules: [{ required: true, message: '请输入接触内容', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '跟踪状态',
          fieldName: 'trackType',
          placeholder: '',
          initialValue: 80581005,
          itemList: this.createDictList('8058')
        },
        {
          type: 'TEXT_AREA',
          label: '战败原因',
          fieldName: 'failingReason',
          placeholder: '',
          rows: 1,
          maxlength: 120
        },
        {
          type: 'DATE',
          dateType: 'exactdate',
          label: '下次跟踪日期',
          fieldName: 'trackNextDate',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '跟踪人',
          fieldName: 'trancerName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '客户反馈',
          fieldName: 'customerFeedback',
          placeholder: '',
          rows: 2,
          maxlength: 120
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          placeholder: '',
          rows: 1,
          maxlength: 120
        }
      ];
    },
    query() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    closeDialog() {
      this.$emit('closeDialog', false);
    },
    async saveDialog() {
      this.saveData = null;
      this.$refs.formPanel.SUBMIT_FORM();

      if (this.saveData != null) {
        let res = await addHistory(this.saveData);
        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '保存成功' });

          this.type = 'refresh';
          this.$emit('saveDialog', this.type);
        } else {
          this.$notify.error({ title: '提示信息', message: res.errMsg });
          return;
        }
      }else{
          this.$notify.warning({ title: '提示信息', message: "请填写必填信息"});
      }
    },
    getClssList(val) {
      this.$set(val, 'tracer', this.name);
      this.saveData = val;
      console.log(this.saveData);
    }
  },
  mounted() {
    this.formList.find(item => item.fieldName === 'proposalCode').initialValue = this.TBcode;
    this.formList.find(item => item.fieldName === 'trancerName').initialValue = getUser();

    // this.formList[0].initialValue = this.TBcode;
    // this.formList[5].initialValue = getUser();

    this.name = getUserId();
    this.query();
  }
};
</script>
<style lang="less" scoped>
.license-warp {
  flex-direction: column;

  .top {
    width: 100%;
    display: flex;
    flex-direction: column;

    .el-row {
      text-align: center;
    }
  }

  .footer {
    text-align: center;
  }
}
</style>
